
<!DOCTYPE HTML>
<html lang="zh-cn" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Ajax 接口化 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Configuration.html" />
    
    
    <link rel="prev" href="Service-layer.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="輸入並搜尋" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    总览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../Getting-started.html">
            
                <a href="../Getting-started.html">
            
                    
                    开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../Features.html">
            
                <a href="../Features.html">
            
                    
                    技术栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../Structure.html">
            
                <a href="../Structure.html">
            
                    
                    目录结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="./">
            
                <a href="./">
            
                    
                    深入了解
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="State-management.html">
            
                <a href="State-management.html">
            
                    
                    谈状态管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="URL-is-soul-of-SPA.html">
            
                <a href="URL-is-soul-of-SPA.html">
            
                    
                    URL 是单页应用的精华
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="Service-layer.html">
            
                <a href="Service-layer.html">
            
                    
                    引入服务层
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.4" data-path="Ajax-interface.html">
            
                <a href="Ajax-interface.html">
            
                    
                    Ajax 接口化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="Configuration.html">
            
                <a href="Configuration.html">
            
                    
                    配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="CORS-and-Proxy.html">
            
                <a href="CORS-and-Proxy.html">
            
                    
                    跨域与代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="Best-practice.html">
            
                <a href="Best-practice.html">
            
                    
                    最佳实践
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../Reference.html">
            
                <a href="../Reference.html">
            
                    
                    参考
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <a target="_blank" href="https://github.com/kenberkeley/vue-demo/issues">
            
                    
                    问题反馈（issues）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" >
            
                <a target="_blank" href="https://github.com/kenberkeley/vue-demo/releases">
            
                    
                    版本迭代（releases）
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本書使用 GitBook 釋出
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Ajax 接口化</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#xA7;-ajax-&#x63A5;&#x53E3;&#x5316;">&#xA7; Ajax &#x63A5;&#x53E3;&#x5316;</h1>
<pre><code>[&#x8DEF;&#x7531;&#x9875;&#x9762;&#x7EC4;&#x4EF6; A [&#x666E;&#x901A;&#x7EC4;&#x4EF6; B [&#x666E;&#x901A;&#x7EC4;&#x4EF6; C]] ...]
      &#x2195;             &#x2195;          &#x2195;
------------------------------------------
| aService      bService   cService      |  &#x670D;&#x52A1;&#x5C42;
------------------------------------------
      &#x2195;             &#x2195;          &#x2195;
------------------------------------------
|                  xhr                   |  Ajax &#x63A5;&#x53E3;
------------------------------------------
                    &#x2195;
                 API &#x670D;&#x52A1;&#x5668;
</code></pre><pre><code class="lang-js"><span class="hljs-comment">/**
 * xhr &#x63A5;&#x53E3;&#xFF08;&#x8BE6;&#x89C1; src/services/xhr/index.js&#xFF09;
 * @param  {String} options.method &#x8BF7;&#x6C42;&#x65B9;&#x6CD5;&#xFF08;&#x9ED8;&#x8BA4;&#x4E3A; get&#xFF09;
 * @param  {String} options.url    &#x8BF7;&#x6C42;&#x8DEF;&#x5F84;&#xFF08;&#x57FA;&#x4E8E; rootPath &#x5730;&#x5740;&#xFF09;
 * @param  {Object} options.body   &#x8BF7;&#x6C42;&#x4F53;&#xFF08;&#x4F8B;&#x5982;&#x540E;&#x7AEF; Express &#x53EF;&#x4F7F;&#x7528; req.body &#x83B7;&#x53D6;&#x8BE5;&#x5BF9;&#x8C61;&#xFF09;
 * @return {Promise}
 */</span>
</code></pre>
<p>&#x5C01;&#x88C5; xhr &#x63A5;&#x53E3;&#x7684;&#x597D;&#x5904;&#x662F;&#x663E;&#x800C;&#x6613;&#x89C1;&#x7684;&#xFF1A;</p>
<ul>
<li>&#x82E5;&#x9879;&#x76EE;&#x5347;&#x7EA7;&#x9700;&#x8981;&#x66FF;&#x6362; Ajax &#x8BF7;&#x6C42;&#x5E93;&#xFF0C;&#x5219;&#x4EC5;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x5B9E;&#x73B0; xhr &#x5373;&#x53EF;&#xFF0C;&#x670D;&#x52A1;&#x5C42;&#x4E0E;&#x7EC4;&#x4EF6;&#x5C42;&#x5B8C;&#x5168;&#x4E0D;&#x9700;&#x8981;&#x6539;&#x52A8;</li>
<li>&#x7EDF;&#x4E00;&#x5316;&#x5904;&#x7406;&#xFF1A;&#x81EA;&#x5B9A;&#x4E49;&#x62E6;&#x622A;&#x3001;API &#x683C;&#x5F0F;&#x53D8;&#x66F4;&#x3001;&#x6570;&#x636E;&#x683C;&#x5F0F;&#x8F6C;&#x6362;&#x3001;&#x9519;&#x8BEF;&#x5904;&#x7406;&#x3001;mock &#x7B49;</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Service-layer.html" class="navigation navigation-prev " aria-label="Previous page: 引入服务层">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Configuration.html" class="navigation navigation-next " aria-label="Next page: 配置">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Ajax 接口化","level":"1.5.4","depth":2,"next":{"title":"配置","level":"1.5.5","depth":2,"path":"development/Configuration.md","ref":"development/Configuration.md","articles":[]},"previous":{"title":"引入服务层","level":"1.5.3","depth":2,"path":"development/Service-layer.md","ref":"development/Service-layer.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"language":"zh-cn","gitbook":"*"},"file":{"path":"development/Ajax-interface.md","mtime":"2016-12-28T14:26:53.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-04-22T13:44:37.529Z"},"basePath":"..","book":{"language":"zh-cn"}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

